#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, q;
int colour[N], father[N], blackCount[N];
/*
colourt[i]: i号节点的颜色，初始都是白色0
blackCount[i]:  i号节点为根的树，一共有多少黑颜色的节点
*/

// 找x节点所在的树的根
int findRoot(int x) {
  return father[x] == x ? x : (father[x] = findRoot(father[x]));
}

// 合并
void merge(int u, int v) {
  u = findRoot(u), v = findRoot(v);
  if (u == v)
    return;
  blackCount[v] += blackCount[u];
  father[u] = v;
}

int main() {
  cin >> n >> q;
  for (int i = 1; i <= n; ++i)
    father[i] = i;

  while (q--) {
    int op, u, v;
    cin >> op >> u;
    if (op == 1) {
      cin >> v;
      merge(u, v);
    } else if (op == 2) {
      if (colour[u] == 0)
        ++blackCount[findRoot(u)];
      else
        --blackCount[findRoot(u)];
      colour[u] ^= 1;
    } else {
      cout << (blackCount[findRoot(u)] == 0 ? "No" : "Yes") << endl;
    }
  }
  return 0;
}
